#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
struct Person
{
	string name;
	int mon, day, hour, min, time;
	bool status;
};
bool cmp(Person p1, Person p2)
{
	return p1.name == p2.name ? p1.time < p2.time : p1.name < p2.name;
}
double count(Person per, int *cost)
{
	double total = cost[per.hour] * per.min + per.day * cost[24] * 60;
	for (int i = 0; i < per.hour; i++)
	{
		total += cost[i] * 60;
	}
	return total / 100;
}
int main()
{
	int cost[25] = {0};
	for (int i = 0; i < 24; ++i)
	{
		scanf("%d", &cost[i]);
		cost[24] += cost[i];
	}
	int n;
	cin >> n;
	vector<Person> per(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> per[i].name;
		scanf("%02d:%02d:%02d:%02d", &per[i].mon, &per[i].day, &per[i].hour, &per[i].min);
		string temp;
		cin >> temp;
		per[i].status = (temp == "on-line") ? true : false;
		per[i].time = per[i].day * 24 * 60 + per[i].hour * 60 + per[i].min;
	}
	sort(per.begin(), per.end(), cmp);
	map<string, vector<Person>> result;
	for (int i = 1; i < n; ++i)
	{
		if (per[i].name == per[i - 1].name && per[i].status == false && per[i - 1].status == true)
		{
			result[per[i - 1].name].push_back(per[i - 1]);
			result[per[i].name].push_back(per[i]);
		}
	}
	for (auto it : result)
	{
		vector<Person> temp = it.second;
		cout << it.first;
		printf(" %02d\n", temp[0].mon);
		double total = 0.0;
		for (int i = 1; i < temp.size(); i += 2)
		{
			double t = count(temp[i], cost) - count(temp[i - 1], cost);
			printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2f\n", temp[i - 1].day, temp[i - 1].hour, temp[i - 1].min, temp[i].day, temp[i].hour, temp[i].min, temp[i].time - temp[i - 1].time, t);
			total += t;
		}
		printf("Total amount: $%.2f\n", total);
	}
	return 0;
}